<?php if(@$type!=="excel") { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Timeline Staff</title>
<?php echo css_asset("printstyle.css"); ?>
</head>
<body>
<?php } else { ?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
                                       xmlns:x="urn:schemas-microsoft-com:office:excel"
                                        xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Timeline Staff</title>
<style>
.table{
        border-collapse:collapse;      
}
</style>
<xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet</x:Name>
    <x:WorksheetOptions>
     <x:Print>
        <x:Gridlines />
     </x:Print>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
 </x:ExcelWorkbook>
</xml>
</head>
<body>
<?php } 
if (count($data_print) > 0 ) {
?>
<table summary='Laporan Timeline Staff' width="100%" class="print">
	<caption>Laporan Timeline Staff</caption>
	<thead>
		<tr>
			<th scope='col' rowspan=2>Nama</th>
			<th scope='col' rowspan=2>Nama Proyek</th>
			<th scope='col' colspan=35>Tanggal Pemasukan</th>
		</tr>
		<tr>
			<?php
			for($i=0;$i<35;$i++){
				$startTime = date("Y-m-d",strtotime("-5 day"));
				echo "<th scope='col'>".date("d",strtotime($startTime." +".$i." day"))."</th>";
			} 
			?>
		</tr>
	</thead>
	<tbody>
		<?php 
		$arr_pic =array();
		foreach($data_print as $print) {
			if ($print->pic_name == ""){
				$arr_pic[] 	= "-";
			}else{
				$arr_pic[] 	= $print->pic_name;
			}
		}
		$arr_pic  = array_count_values($arr_pic);
		$namaTmp = null;  $i=0; $a = 0;
		foreach($data_print as $print) { $i++; ?>
		<?php 
		if ($print->pic_name == ""){
			$picname = "-"; 
		}else{
			$picname = $print->pic_name; 
		}
		$rowspan = "";
		if ($namaTmp == $picname) 
			$picname = "";
		else { 
			$namaTmp  = $picname;
			$rowspan = "rowspan='".$arr_pic[$picname]."'";
		}$a++; ?>
		<tr <?php if(@$data_print[$a]->pic_name !=  $print->pic_name ) echo 'style="border-bottom:2px solid #000;"'; ?> >
		<?php if ($picname != ""){ ?>
			<td <?php echo $rowspan; ?>><?php echo $picname ; ?></td>
		<?php } ?>
			<td><?php echo $print->jadwal_alias; ?></td>
			<?php
				for($i=0;$i<35;$i++){
					$startTime = date("Y-m-d",strtotime("-5 day"));
					$dateLaporan = date("Y-m-d",strtotime($startTime." +".$i." day"));
					$dateSekarang = date("Y-m-d");
					$datePemasukan =  date("Y-m-d",strtotime($print->jadwal_tglpemasukan));
					// memecah tanggal untuk mendapatkan bagian tanggal, bulan dan tahun
					// dari tanggal pertama

					$pecah1 = explode("-", $dateSekarang);
					$date1 = $pecah1[2];
					$month1 = $pecah1[1];
					$year1 = $pecah1[0];

					// memecah tanggal untuk mendapatkan bagian tanggal, bulan dan tahun
					// dari tanggal kedua

					$pecah2 = explode("-", $datePemasukan);
					$date2 = $pecah2[2];
					$month2 = $pecah2[1];
					$year2 =  $pecah2[0];

					// menghitung JDN dari masing-masing tanggal

					$jd1 = GregorianToJD($month1, $date1, $year1);
					$jd2 = GregorianToJD($month2, $date2, $year2);

					// hitung selisih hari kedua tanggal

					$selisih = $jd2 - $jd1;
					$warna = "style='background:#fff'";
					if ($selisih  <= $batas_merah[0]->nvalue1 ) 
						$warna = "style='background:#f00'";
					else if ($selisih  > $batas_merah[0]->nvalue1  AND $selisih  <= $batas_kuning[0]->nvalue1 ) 
						$warna = "style='background:#ff0'";
					else if ($selisih  > $batas_kuning[0]->nvalue1  AND $selisih  <= $batas_hijau[0]->nvalue1 ) 
						$warna = "style='background:#0f0'";
					else
						$warna = "style='background:#00f'";
					
					if ($datePemasukan == $dateLaporan){
						echo "<td ".$warna ."></td>";
					}else{
						if ($dateLaporan == $dateSekarang){
							echo "<td style='background:#eee;' >&nbsp;</td>";	
						}else{
							echo "<td>&nbsp;</td>";
						}
					}
				} 
			?>
		</tr>
		<?php } ?>
	</tbody>
	</table>	<?php  }else{ ?>
		<center><b>Tidak ada data yang ditemukan!</b></center>
		<?php } ?>
</body>
</html>